package com.snail.ron.util;

import com.mongodb.MongoClient;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;

/**
 * @author xueguoping
 * @desc: TODO
 * @date 2022/3/247:55 PM
 */
public class MongDBUtil {
    public static void main(String[] args) throws Exception{
        MongoClient client = new MongoClient("localhost", 27017);
        MongoDatabase ron = client.getDatabase("rontwo");
        System.out.println("Connect to database successfully");
        //ron.createCollection("family_info");
        //System.out.println("集合创建成功");
        MongoCollection<Document> ronCollection = ron.getCollection("base_info");
        FindIterable<Document> documents = ronCollection.find();
        MongoCursor<Document> iterator = documents.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }
}
